import utils from '../util/utils'
import http from '../util/http/axios'

window.onload = function() {
  let rep = ['index', 'pc', 'mobile'].filter(e => {
    if (window.location.href.includes(e)) {
      return true
    }
  })
  if (rep.length || window.location.pathname === '/') {
    if (utils.isMobile() && !location.href.includes('mobile')) {
      utils.redirection('mobile.html')
    } else if (!utils.isMobile() && !location.href.includes('pc')) {
      utils.redirection('pc.html')
    }
  }

  // token验证
  http.get('/auth/verify')
    .then(
      res => {
        if (res.code === 200) {
          sessionStorage.setItem('tokenInfo', JSON.stringify(res.data))
        } else {
          console.log('token认证失败')
          window.location.href = '/index.html'
        }
      }
    )
}
